import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

var _this = new Vue();

const store = new Vuex.Store({
	state: {
		userinfo: {}, //用户信息
		indexTotalData: '', // 首页统计数据
		machinelist: [], // 加注机列表
		bindedWxInfo: {}, // 已绑定的提现微信信息

	},
	mutations: {
		setUserinfo(state, data) {
			state.userinfo = data;
		},
		//修改缓存值
		setIndexData(state, data) {
			state.indexTotalData = data;
		},
		setMachinelist(state, data) {
			state.machinelist = data.lstFillMachine;
		},
		setBindedWxInfo(state, data) {
			state.bindedWxInfo = data;
		},
		
	},
	getters: {

	},
	actions: {
		async requestBindedWxInfo({
			commit
		}) {
			const res = await _this.$u.api._getBindedInfo({
				userMain: this.state.userinfo.isMain
			});
			if (!res.payeeOpenId) {
				setTimeout(() => {
					uni.showModal({
						title: '提示',
						content: '当前账号未绑定微信收款账户，请尽快进行绑定，否则将影响系统打款操作！',
						confirmText: '前往绑定',
						confirmColor: '#37B736',
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/accountManage/bindWxAccount/bindWxAccount'
								})
							}
						}
					})
				}, 888)
			} else if (res.payeeOpenId && res.isMe == 'No') {
				setTimeout(() => {
					uni.showModal({
						title: '提示',
						content: '当前登录微信与已绑定的收款微信号不一致，是否需要跟换绑定！',
						confirmText: '更换绑定',
						confirmColor: '#37B736',
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/accountManage/bindWxAccount/bindWxAccount'
								})
							}
						}
					})
				}, 888)
			}
			commit('setBindedWxInfo', res);
		}
	}
});

Vue.prototype.$store = store;
